package com.wxb.annotationlog.service;

import com.alibaba.fastjson.JSON;
import com.wxb.annotationlog.annotation.AnnotationLog;
import com.wxb.annotationlog.cache.AnnotaionLogCache;
import com.wxb.annotationlog.entity.AnnotationLogInfoWithBLOBs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Description 测试注解实现类
 * @Author Major
 * @Date 2020/6/1 13:53
 */
@Service
public class TestAnnotationService {

    Logger logger = LoggerFactory.getLogger(TestAnnotationService.class);

    @AnnotationLog("测试正常方法")
    public String testNormal(Map<String,String> map) throws Exception{
        return "hello " + map.toString();
    }

    @AnnotationLog("测试异常方法")
    public String testException(Map<String,String> map) throws Exception{
        Integer id = null;
        if (id == 0){
            return "异常";
        }
        return "hello " + map.toString();
    }

    public void queryCacheLog(){
        List<AnnotationLogInfoWithBLOBs> loggerCaches =  AnnotaionLogCache.loggerCache;
        logger.info("缓存日志信息>>>" + JSON.toJSONString(loggerCaches));
    }

}
